window.onload = setupLightbox;

var lightboxOverlay;
var lightboxImage;
var captionParagraph;

//sets up light box to open on click of all link with rel ="LightBox"
function setupLightbox()
{
	for(i in document.links)
	{
		if(document.links[i].rel == "LightBox")
		{
			document.links[i].onclick = showLightbox;
		}
	}
}

//display lightbox
function showLightbox()
{
	lightboxOverlay = document.createElement("div");
	lightboxImage = document.createElement("img");
	
	lightboxOverlay.style.position = "fixed"; //fixed with screen, doesn't move with scroll
	lightboxOverlay.style.top = lightboxOverlay.style.left = "0"; //top left corner positioning
	lightboxOverlay.style.width = lightboxOverlay.style.height = "100%"; //full size of screen
	
	lightboxOverlay.style.background = "#000";
	lightboxOverlay.style.opacity = "0. 5";
	lightboxOverlay.style.filter = "alpha(opacity = 10)";

	document.body.appendChild(lightboxOverlay);
	
	lightboxImage.onload = showImage;
	lightboxOverlay.onclick = closeLightbox;
	lightboxImage.src = this.href;
	
	return false;
}

//display image in lightbox
function showImage()
{
	lightboxImage.style.position = "fixed";
	lightboxImage.style.top = lightboxImage.style.left = "50%";
	lightboxImage.style.marginLeft = -lightboxImage.width/2 + "px";
	lightboxImage.style.marginTop = -lightboxImage.height/2 + "px";
	lightboxImage.style.border = "10px solid #fff";
	document.body.appendChild(lightboxImage);
}

//close up the light box
function closeLightbox()
{
	lightboxImage.style.opacity = lightboxOverlay.style.opacity = "0";
	setTimeout( function()
	{
		lightboxImage.parentNode.removeChild(lightboxImage);
		lightboxOverlay.parentNode.removeChild(lightboxOverlay);
	}, 1);
}	


















